﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace HDSmartCommunity.BUS
{
    public class LogHelper
    {
        static string path = AppDomain.CurrentDomain.BaseDirectory;
        static object loglocker = new object();
        public static void Log(string message)
        {
            try
            {
                lock (loglocker)
                {
                    string dirpath = path + @"/wwwroot/Log";
                    string filepath = dirpath + "/Log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";


                    //生成目录
                    //创建文件夹
                    if (Directory.Exists(dirpath) == false)//如果不存在就创建file文件夹
                    {
                        Directory.CreateDirectory(dirpath);
                    }

                    // 判断文件是否存在，不存在则创建，否则读取值显示到txt文档
                    if (!System.IO.File.Exists(filepath))
                    {
                        FileStream fs1 = new FileStream(filepath, FileMode.Create, FileAccess.Write);//创建写入文件 
                        fs1.Close();
                    }

                    File.AppendAllTextAsync(filepath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + message + "\r\n");
                }
            }
            catch
            {

            }
        }
    }

    public class PZLogHelper
    {
        static string path = AppDomain.CurrentDomain.BaseDirectory;
        static object loglocker = new object();
        public static void Log(string message, string number)
        {
            lock (loglocker)
            {
                string dirpath = path + @"/wwwroot/Log/" + number;
                string filepath = dirpath + "/Log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";


                //生成目录
                //创建文件夹
                if (Directory.Exists(dirpath) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(dirpath);
                }

                // 判断文件是否存在，不存在则创建，否则读取值显示到txt文档
                if (!System.IO.File.Exists(filepath))
                {
                    FileStream fs1 = new FileStream(filepath, FileMode.Create, FileAccess.Write);//创建写入文件 
                    fs1.Close();
                }

                File.AppendAllTextAsync(filepath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + message + "\r\n");
            }
        }
    }

    public class DYLogHelper
    {
        static string path = AppDomain.CurrentDomain.BaseDirectory;
        static object loglocker = new object();
        public static void Log(string message, string number)
        {
            lock (loglocker)
            {
                string dirpath = path + @"/wwwroot/TestLog/" + number;
                string filepath = dirpath + "/Log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";


                //生成目录
                //创建文件夹
                if (Directory.Exists(dirpath) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(dirpath);
                }

                // 判断文件是否存在，不存在则创建，否则读取值显示到txt文档
                if (!System.IO.File.Exists(filepath))
                {
                    FileStream fs1 = new FileStream(filepath, FileMode.Create, FileAccess.Write);//创建写入文件 
                    fs1.Close();
                }

                File.AppendAllTextAsync(filepath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "," + message + "\r\n");
            }
        }
    }

    public class DataSaveLogHelper
    {
        static string path = AppDomain.CurrentDomain.BaseDirectory;
        static object loglocker = new object();
        public static void Log(string message)
        {
            lock (loglocker)
            {
                string dirpath = path + @"/wwwroot/TestLog/Network";
                string filepath = dirpath + "/Log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";


                //生成目录
                //创建文件夹
                if (Directory.Exists(dirpath) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(dirpath);
                }

                // 判断文件是否存在，不存在则创建，否则读取值显示到txt文档
                if (!System.IO.File.Exists(filepath))
                {
                    FileStream fs1 = new FileStream(filepath, FileMode.Create, FileAccess.Write);//创建写入文件 
                    fs1.Close();
                }

                File.AppendAllTextAsync(filepath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "," + message + "\r\n");
            }
        }
    }

    public class SerialDataSaveLogHelper
    {
        static string path = AppDomain.CurrentDomain.BaseDirectory;
        static object loglocker = new object();
        public static void Log(string message)
        {
            lock (loglocker)
            {
                string dirpath = path + @"/wwwroot/TestLog/Serial";
                string filepath = dirpath + "/Log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";


                //生成目录
                //创建文件夹
                if (Directory.Exists(dirpath) == false)//如果不存在就创建file文件夹
                {
                    Directory.CreateDirectory(dirpath);
                }

                // 判断文件是否存在，不存在则创建，否则读取值显示到txt文档
                if (!System.IO.File.Exists(filepath))
                {
                    FileStream fs1 = new FileStream(filepath, FileMode.Create, FileAccess.Write);//创建写入文件 
                    fs1.Close();
                }

                File.AppendAllTextAsync(filepath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "," + message + "\r\n");
            }
        }
    }

    public class KoneLogHelper
    {
        static string path = AppDomain.CurrentDomain.BaseDirectory;
        static object loglocker = new object();
        public static void Log(string message)
        {
            try
            {
                lock (loglocker)
                {
                    string dirpath = path + @"/wwwroot/Log";
                    string filepath = dirpath + "/Log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";


                    //生成目录
                    //创建文件夹
                    if (Directory.Exists(dirpath) == false)//如果不存在就创建file文件夹
                    {
                        Directory.CreateDirectory(dirpath);
                    }

                    // 判断文件是否存在，不存在则创建，否则读取值显示到txt文档
                    if (!System.IO.File.Exists(filepath))
                    {
                        FileStream fs1 = new FileStream(filepath, FileMode.Create, FileAccess.Write);//创建写入文件 
                        fs1.Close();
                    }

                    File.AppendAllTextAsync(filepath, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + ":" + message + "\r\n");
                }
            }
            catch
            {

            }
        }
    }
}
